package com.camel.base.exceptions;

import cn.dev33.satoken.exception.NotLoginException;
import com.camel.core.entity.Result;
import com.camel.core.utils.ResultUtil;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author camel
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 全局异常拦截
     * @param e
     * @param req
     * @param resp
     * @throws IOException
     */
    @ExceptionHandler
    public Result handlerException(RuntimeException e, HttpServletRequest req, HttpServletResponse resp) throws IOException {
        e.printStackTrace();
        return ResultUtil.error(500, e.getMessage());
    }
}
